package ynu.beggar.server.entities.PO;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import ynu.beggar.server.entities.DO.UserBasicInfoDO;
import ynu.beggar.server.entities.DO.UserChangeInfoDO;
import ynu.beggar.server.entities.DO.UserRegisterDO;
import ynu.beggar.server.utils.CommonUtils;

import javax.persistence.*;
import java.io.Serializable;

@Entity
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "user_info", schema = "ynu_beggar")
public class UserInfoPO implements Serializable {
    private int userId;
    private String userName;
    private String userPw;
    private String headImgUrl;
    private String stuCardUrl;
    private String userGender;
    private String campus;
    private String dormitory;
    private String roomNum;
    private String stuId;
    private String educationLevel;
    private Integer grade;
    private String college;
    private String major;
    private String phoneNum;
    private String qqNum;
    private String wechatAccount;
    private String detailInfoRule;
    private Integer credibility;
    private Integer del;

    public UserInfoPO(UserRegisterDO userRegisterDO) {
        this.userName = userRegisterDO.getRgName();
        this.campus = userRegisterDO.getRgCampus();
        this.stuId = userRegisterDO.getRgStuId();
        this.userPw = CommonUtils.MD5(userRegisterDO.getRgPw());
    }

    public UserInfoPO(UserChangeInfoDO userChangeInfoDO, UserInfoPO userInfoPO) {
        this.userId = userInfoPO.getUserId();
        this.userPw = userInfoPO.getUserPw();
        this.headImgUrl = userInfoPO.getHeadImgUrl();
        this.detailInfoRule = userInfoPO.getDetailInfoRule();
        this.credibility = userInfoPO.getCredibility();
        this.del = userInfoPO.getDel();
        this.userName = userChangeInfoDO.getUserName();
        this.stuCardUrl = userChangeInfoDO.getStuCardUrl();
        this.userGender = userChangeInfoDO.getUserGender();
        this.campus = userChangeInfoDO.getCampus();
        this.dormitory = userChangeInfoDO.getDormitory();
        this.roomNum = userChangeInfoDO.getRoomNum();
        this.stuId = userChangeInfoDO.getStuId();
        this.educationLevel = userChangeInfoDO.getEducationLevel();
        this.grade = userChangeInfoDO.getGrade();
        this.college = userChangeInfoDO.getCollege();
        this.major = userChangeInfoDO.getMajor();
        this.phoneNum = userChangeInfoDO.getPhoneNum();
        this.qqNum = userChangeInfoDO.getQqNum();
        this.wechatAccount = userChangeInfoDO.getWechatAccount();
    }

    @Id
    @Column(name = "user_id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    @Basic
    @Column(name = "user_name")
    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    @Basic
    @Column(name = "user_pw")
    public String getUserPw() {
        return userPw;
    }

    public void setUserPw(String userPw) {
        this.userPw = userPw;
    }

    @Basic
    @Column(name = "head_img_url")
    public String getHeadImgUrl() {
        return headImgUrl;
    }

    public void setHeadImgUrl(String headImgUrl) {
        this.headImgUrl = headImgUrl;
    }

    @Basic
    @Column(name = "stu_card_url")
    public String getStuCardUrl() {
        return stuCardUrl;
    }

    public void setStuCardUrl(String stuCardUrl) {
        this.stuCardUrl = stuCardUrl;
    }

    @Basic
    @Column(name = "user_gender")
    public String getUserGender() {
        return userGender;
    }

    public void setUserGender(String userGender) {
        this.userGender = userGender;
    }

    @Basic
    @Column(name = "campus")
    public String getCampus() {
        return campus;
    }

    public void setCampus(String campus) {
        this.campus = campus;
    }

    @Basic
    @Column(name = "dormitory")
    public String getDormitory() {
        return dormitory;
    }

    public void setDormitory(String dormitory) {
        this.dormitory = dormitory;
    }

    @Basic
    @Column(name = "room_num")
    public String getRoomNum() {
        return roomNum;
    }

    public void setRoomNum(String roomNum) {
        this.roomNum = roomNum;
    }

    @Basic
    @Column(name = "stu_id")
    public String getStuId() {
        return stuId;
    }

    public void setStuId(String stuId) {
        this.stuId = stuId;
    }

    @Basic
    @Column(name = "education_level")
    public String getEducationLevel() {
        return educationLevel;
    }

    public void setEducationLevel(String educationLevel) {
        this.educationLevel = educationLevel;
    }

    @Basic
    @Column(name = "grade")
    public Integer getGrade() {
        return grade;
    }

    public void setGrade(Integer grade) {
        this.grade = grade;
    }

    @Basic
    @Column(name = "college")
    public String getCollege() {
        return college;
    }

    public void setCollege(String college) {
        this.college = college;
    }

    @Basic
    @Column(name = "major")
    public String getMajor() {
        return major;
    }

    public void setMajor(String major) {
        this.major = major;
    }

    @Basic
    @Column(name = "phone_num")
    public String getPhoneNum() {
        return phoneNum;
    }

    public void setPhoneNum(String phoneNum) {
        this.phoneNum = phoneNum;
    }

    @Basic
    @Column(name = "qq_num")
    public String getQqNum() {
        return qqNum;
    }

    public void setQqNum(String qqNum) {
        this.qqNum = qqNum;
    }

    @Basic
    @Column(name = "wechat_account")
    public String getWechatAccount() {
        return wechatAccount;
    }

    public void setWechatAccount(String wechatAccount) {
        this.wechatAccount = wechatAccount;
    }

    @Basic
    @Column(name = "detail_info_rule")
    public String getDetailInfoRule() {
        return detailInfoRule;
    }

    public void setDetailInfoRule(String detailInfoRule) {
        this.detailInfoRule = detailInfoRule;
    }

    @Basic
    @Column(name = "credibility")
    public Integer getCredibility() {
        return credibility;
    }

    public void setCredibility(Integer credibility) {
        this.credibility = credibility;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        UserInfoPO userInfoPO = (UserInfoPO) o;

        if (userId != userInfoPO.userId) return false;
        if (userName != null ? !userName.equals(userInfoPO.userName) : userInfoPO.userName != null) return false;
        if (userPw != null ? !userPw.equals(userInfoPO.userPw) : userInfoPO.userPw != null) return false;
        if (headImgUrl != null ? !headImgUrl.equals(userInfoPO.headImgUrl) : userInfoPO.headImgUrl != null)
            return false;
        if (stuCardUrl != null ? !stuCardUrl.equals(userInfoPO.stuCardUrl) : userInfoPO.stuCardUrl != null)
            return false;
        if (userGender != null ? !userGender.equals(userInfoPO.userGender) : userInfoPO.userGender != null)
            return false;
        if (campus != null ? !campus.equals(userInfoPO.campus) : userInfoPO.campus != null) return false;
        if (dormitory != null ? !dormitory.equals(userInfoPO.dormitory) : userInfoPO.dormitory != null) return false;
        if (roomNum != null ? !roomNum.equals(userInfoPO.roomNum) : userInfoPO.roomNum != null) return false;
        if (stuId != null ? !stuId.equals(userInfoPO.stuId) : userInfoPO.stuId != null) return false;
        if (educationLevel != null ? !educationLevel.equals(userInfoPO.educationLevel) : userInfoPO.educationLevel != null)
            return false;
        if (grade != null ? !grade.equals(userInfoPO.grade) : userInfoPO.grade != null) return false;
        if (college != null ? !college.equals(userInfoPO.college) : userInfoPO.college != null) return false;
        if (major != null ? !major.equals(userInfoPO.major) : userInfoPO.major != null) return false;
        if (phoneNum != null ? !phoneNum.equals(userInfoPO.phoneNum) : userInfoPO.phoneNum != null) return false;
        if (qqNum != null ? !qqNum.equals(userInfoPO.qqNum) : userInfoPO.qqNum != null) return false;
        if (wechatAccount != null ? !wechatAccount.equals(userInfoPO.wechatAccount) : userInfoPO.wechatAccount != null)
            return false;
        if (detailInfoRule != null ? !detailInfoRule.equals(userInfoPO.detailInfoRule) : userInfoPO.detailInfoRule != null)
            return false;
        if (credibility != null ? !credibility.equals(userInfoPO.credibility) : userInfoPO.credibility != null)
            return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = userId;
        result = 31 * result + (userName != null ? userName.hashCode() : 0);
        result = 31 * result + (userPw != null ? userPw.hashCode() : 0);
        result = 31 * result + (headImgUrl != null ? headImgUrl.hashCode() : 0);
        result = 31 * result + (stuCardUrl != null ? stuCardUrl.hashCode() : 0);
        result = 31 * result + (userGender != null ? userGender.hashCode() : 0);
        result = 31 * result + (campus != null ? campus.hashCode() : 0);
        result = 31 * result + (dormitory != null ? dormitory.hashCode() : 0);
        result = 31 * result + (roomNum != null ? roomNum.hashCode() : 0);
        result = 31 * result + (stuId != null ? stuId.hashCode() : 0);
        result = 31 * result + (educationLevel != null ? educationLevel.hashCode() : 0);
        result = 31 * result + (grade != null ? grade.hashCode() : 0);
        result = 31 * result + (college != null ? college.hashCode() : 0);
        result = 31 * result + (major != null ? major.hashCode() : 0);
        result = 31 * result + (phoneNum != null ? phoneNum.hashCode() : 0);
        result = 31 * result + (qqNum != null ? qqNum.hashCode() : 0);
        result = 31 * result + (wechatAccount != null ? wechatAccount.hashCode() : 0);
        result = 31 * result + (detailInfoRule != null ? detailInfoRule.hashCode() : 0);
        result = 31 * result + (credibility != null ? credibility.hashCode() : 0);
        return result;
    }

    @Basic
    @Column(name = "del")
    public Integer getDel() {
        return del;
    }

    public void setDel(Integer del) {
        this.del = del;
    }
}
